<template>
  <div>
    <el-form-item
      v-if="type === 'EXPORT'"
      label="填写规则:"
      prop="displayRule"
      :rules="[
        {
          required: true,
          message: '请选择规则',
          trigger: 'change',
        },
      ]"
    >
      <LabelExpression
        style="width: 500px"
        v-model="value.displayRule"
        :fields="value.relation_modelList"
      />
    </el-form-item>
    <el-form-item
      v-if="type === 'IMPORT'"
      label="导入字段:"
      prop="filterFields"
      :rules="[
        {
          required: true,
          message: '选择导入字段',
          trigger: 'change',
        },
      ]"
    >
      <el-select
        multiple
        v-model="value.filterFields"
        placeholder="请选择"
        style="width: 500px"
      >
        <el-option
          v-for="item in value.relation_modelList"
          :key="item.id"
          :value="item.code"
          :label="item.name + '(' + item.code + ')'"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item v-if="type === 'IMPORT'" label="导入字段格式:">
      <div>请以“#”作为分隔符连接所选字段。</div>
      <div>例：{{ example }}</div>
    </el-form-item>
  </div>
</template>
<script>
import LabelExpression from "@/components/LabelExpression"
export default {
  name: "RelationConfig",
  props: {
    value: {
      type: Object,
      default: () => {
        return {}
      },
    },
    type: {
      type: String,
      default: "",
    },
  },
  components: {
    LabelExpression,
  },
  computed: {
    example() {
      let str = ""
      this.value.filterFields.forEach((i) => {
        let c = this.value.relation_modelList.find((item) => item.code === i)
        str += `${c.name}#`
      })
      return str.substring(0, str.length - 1)
    },
  },
  data() {
    return {}
  },
  methods: {},
}
</script>
